import pygame
from .. import constants
from . import coin


class Info:
    def __init__(self, state, game_info):
        self.state = state
        self.game_info = game_info
        self.create_state_labels()
        self.create_info_labels()
        self.flash_coin = coin.FlashingCoin()

    def create_state_labels(self):
        self.state_labels = []
        if self.state == "main_menu":
            self.state_labels.append((self.create_labels("1 PLAYER GAME"), (272, 360)))
            self.state_labels.append((self.create_labels("2 PLAYER GAME"), (272, 405)))
            self.state_labels.append((self.create_labels("TOP"), (290, 465)))
            self.state_labels.append((self.create_labels("000000"), (400, 465)))
        elif self.state == "load_screen":
            self.state_labels.append((self.create_labels("WORLD"), (280, 200)))
            self.state_labels.append((self.create_labels("1 - 1"), (430, 200)))
            self.state_labels.append((self.create_labels("X    {}".format(self.game_info["lives"])), (380, 280)))
        elif self.state == "game_over":
            self.state_labels.append((self.create_labels("GAME OVER"), (280, 300)))

    def create_info_labels(self):
        self.info_labels = []
        self.info_labels.append((self.create_labels("MARIO"), (75, 30)))
        self.info_labels.append((self.create_labels("WORLD"), (450, 30)))
        self.info_labels.append((self.create_labels("TIME"), (625, 30)))
        self.info_labels.append((self.create_labels("000000"), (75, 55)))
        self.info_labels.append((self.create_labels("x00"), (300, 55)))
        self.info_labels.append((self.create_labels("1 - 1"), (480, 55)))

    def create_labels(self, label, size=40, width_scale=1.25, height_scale=1):
        font = pygame.font.SysFont(constants.FONT, size)
        label_image = font.render(label, False, (255, 255, 255))
        return label_image

    def update(self):
        self.flash_coin.update()

    def draw(self, surface):
        # 画出静态封面字
        for label in self.state_labels:
            surface.blit(*label)
        for label in self.info_labels:
            surface.blit(*label)

        # 画出闪烁金币
        surface.blit(self.flash_coin.image, self.flash_coin.rect)
